package com.all.play.myapplication.adapter.inneradapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.all.play.myapplication.Bean.NewsResaultBeanData;
import com.all.play.myapplication.utils.Constants;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/4/20.
 * Time: 2018/4/20  14:16
 */

public class MyActAdapter extends PagerAdapter {
    private Context mContext;
    private List<NewsResaultBeanData.ResultBean.ActInfoBean> act_info;

    public MyActAdapter(Context mContext, List<NewsResaultBeanData.ResultBean.ActInfoBean> act_info) {

        this.mContext = mContext;
        this.act_info = act_info;
    }

    @Override
    public int getCount() {
        return act_info==null?0:act_info.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(mContext);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        container.addView(imageView);
        Glide.with(mContext).load(Constants.BASE_URl_IMAGE+act_info.get(position).getIcon_url()).into(imageView);
        Log.i("NewsResaultBe", "setdata: " + Constants.BASE_URl_IMAGE+act_info.get(position).getIcon_url());
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, "点击图片", Toast.LENGTH_SHORT).show();
            }
        });
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
